package com.zhang.common.util.md5;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


@Slf4j
public class Md5Util {
    private static final String slat = UUID.randomUUID().toString();

    //私有化构造方法
    private Md5Util() {

    }

    /**传入一个字符串，返回这个字符串md5的值
     * @param str
     * @return {@link Map}<{@link String}, {@link String}>
     */
    public static Map<String, String> getMD5Slat(String str) {
        String base = str + slat;
        String md5 = DigestUtils.md5DigestAsHex(base.getBytes());
        Map<String, String> map = new HashMap<>();
        map.put("slat", slat);
        map.put("value", md5);
        return map;
    }

    public static String getMD5(String str) {
        String md5 = DigestUtils.md5DigestAsHex(str.getBytes());
        return md5;
    }
}
